package com.jwd.avmanager.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 public class MP4DurationUtil {
    public static long getDuration(String filePath) {
        try {

            ProcessBuilder processBuilder = new ProcessBuilder("ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", filePath);
            Process process = processBuilder.start();
             BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String durationString = reader.readLine();
             if (durationString != null) {
                return (long) Double.parseDouble(durationString);
            } else {
                DebugLogger.info("Failed to get duration.");
            }
             process.destroy();
        } catch (IOException e) {
            e.printStackTrace();
        }
         return (long) 0.0;
    }


}
